////////////////////////////////////////////////////////////////////////////
//	Copyright: A. Riazi (3 June 2003)
//
//	Email: a.riazi@misbah3com.com
//
//	This code may be used in compiled form in any way you desire. This
//	file may be redistributed unmodified by any means PROVIDING it is 
//	not sold for profit without the authors written consent, and 
//	providing that this notice and the authors name is included.
//
//	This file is provided 'as is' with no expressed or implied warranty.
//	The author accepts no liability if it causes any damage to your computer.
//
//	Do expect bugs.
//	Please let me know of any bugs/mods/improvements.
//	and I will try to fix/incorporate them into this file.
//	Enjoy!
//
//	Description: CStatic Derived Class for playing Gif Animated files.
//
//  Credit: Most of works done by Juan Soulie <jsoulie@cplusplus.com>
////////////////////////////////////////////////////////////////////////////

#ifndef _GIF_ANIMATION_H_
#define _GIF_ANIMATION_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// GifAnimation.h : header file
//

typedef char int8_t;
#define B16_SIZE (352/16*288/16)
#define B8_SIZE (352/8*288/8)
#define B4_SIZE (352/4*288/4)

/////////////////////////////////////////////////////////////////////////////
// CYUVPlayback window
typedef struct {
	int8_t v;		// valid or not
	int8_t mvx;	// motion vector x
	int8_t mvy;	// motion vector y
} MB_DESC;
typedef struct {
	MB_DESC b16[B16_SIZE];
	MB_DESC b8[B8_SIZE];
	MB_DESC b4[B4_SIZE];
} BLOCK_DESC_TYPE;

class CYUVPlayback : public CStatic
{
// Construction
public:
	CYUVPlayback();

	//{{AFX_DATA(CYUVAnalyzerDlg)
	enum { IDD = 0 };
	//}}AFX_DATA

// Attributes
public:
	
// Operations
public:
	unsigned char * Y, * Cb, * Cr;

protected:

public:

private:
	void ShowMotionVector(CDC *pDC);
	void ShowGrid(CDC *pDC);
	void ShowYImage(CDC *pDC);
	void ShowUImage(CDC *pDC);
	void ShowVImage(CDC *pDC);
	void ShowColorImage(CDC *pDC);
	BOOL	bHaveFile;
	char	sPathName[1024];
	CFile *	m_pFile;
	int		iTotalFrameNumber;
	int		iCurrFrameNumber;
	int		iWidth;
	int		iHeight;
	int		bColorful;
	BOOL	bShowMV;
	BOOL	bShowMV_backup;
	BOOL	bShowGrid;

	unsigned char * RGBbuf;
	BLOCK_DESC_TYPE bs;	// block structure
	BITMAPINFO * BmpInfo;

	void GetYUVData(void);
	void GetMVData(void);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CYUVPlayback)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
public:
	void GoToFrame(int number);
	void PrevFrame(void);
	void SetColorful(int colorful);
	void SetShowMV(BOOL bMV);
	void SetShowGrid(BOOL grid);
	void NextFrame(void);
	void ContinuePlay(void);
	void StartPlay(void);
	void PausePlay(void);
	int ReStart(void);
	void SetYUVSize(int width, int height);
	void SetPathName(char * pathname);
	virtual ~CYUVPlayback();

	// Generated message map functions
protected:
	//{{AFX_MSG(CYUVPlayback)
	afx_msg void OnPaint();
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // _GIF_ANIMATION_H_
